home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / DIRSCAN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-23  |  989 b   |  52 lines

  1. /*
  2.  
  3.   Alec Russell 1995
  4.  
  5.   A simple example of scanning down through a directory tree.
  6.  
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dir.h>
  12. #include <dos.h>
  13.  
  14.  
  15. /* ---------------------- scan_files() --------------- September 20,1993 */
  16. void scan_files(char *path)
  17. {
  18.    struct ffblk fb;
  19.    char start_path[90];
  20.  
  21.    getcwd(start_path, 90);
  22.    if ( chdir(path) )
  23.       {
  24.       printf("ERROR changing to %s\n", path);
  25.       exit(1);
  26.       }
  27.  
  28.    memset((char *)&fb, 0, sizeof(fb));
  29.  
  30.    // recursively scan down thru the directory tree
  31.    if ( !findfirst("*.*", &fb, FA_DIREC) )
  32.       {
  33.       do
  34.          {
  35.          if ( *fb.ff_name != '.'  )
  36.             {
  37.             if ( (fb.ff_attrib & FA_DIREC) )
  38.                scan_files(fb.ff_name);
  39.             else
  40.                {
  41.                printf("File: %-15.15s", fb.ff_name);
  42.                }
  43.             }
  44.  
  45.          }
  46.       while ( !findnext(&fb) );
  47.       }
  48.  
  49.    chdir(start_path);
  50. }
  51.  
  52.